<?php

namespace App\Http\Controllers\Backend;

use App\DataTables\ItemManagerDataTable;
use App\Http\Requests;
use App\Http\Requests\CreateItemManagerRequest;
use App\Http\Requests\UpdateItemManagerRequest;
use App\Repositories\ItemManagerRepository;
use Flash;
use App\Http\Controllers\AppBaseController;
use Response;

class ItemManagerController extends AppBaseController
{
    /** @var  ItemManagerRepository */
    private $itemManagerRepository;

    public function __construct(ItemManagerRepository $itemManagerRepo)
    {
        $this->itemManagerRepository = $itemManagerRepo;
    }

    /**
     * Display a listing of the ItemManager.
     *
     * @param ItemManagerDataTable $itemManagerDataTable
     * @return Response
     */
    public function index(ItemManagerDataTable $itemManagerDataTable)
    {
        return $itemManagerDataTable->render('backend.item_managers.index');
    }

    /**
     * Show the form for creating a new ItemManager.
     *
     * @return Response
     */
    public function create()
    {
        return view('backend.item_managers.create');
    }

    /**
     * Store a newly created ItemManager in storage.
     *
     * @param CreateItemManagerRequest $request
     *
     * @return Response
     */
    public function store(CreateItemManagerRequest $request)
    {
        $input = $request->all();

        $itemManager = $this->itemManagerRepository->create($input);

        Flash::success(trans('flash.controller.save_success', ['model' => 'Item Manager']));

        return redirect(route('itemManagers.index'));
    }

    /**
     * Display the specified ItemManager.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $itemManager = $this->itemManagerRepository->findWithoutFail($id);

        if (empty($itemManager)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Item Manager']));

            return redirect(route('itemManagers.index'));
        }

        return view('backend.item_managers.show')->with('itemManager', $itemManager);
    }

    /**
     * Show the form for editing the specified ItemManager.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $itemManager = $this->itemManagerRepository->findWithoutFail($id);

        if (empty($itemManager)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Item Manager']));

            return redirect(route('itemManagers.index'));
        }

        return view('backend.item_managers.edit')->with('itemManager', $itemManager);
    }

    /**
     * Update the specified ItemManager in storage.
     *
     * @param  int              $id
     * @param UpdateItemManagerRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateItemManagerRequest $request)
    {
        $itemManager = $this->itemManagerRepository->findWithoutFail($id);

        if (empty($itemManager)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Item Manager']));

            return redirect(route('itemManagers.index'));
        }

        $itemManager = $this->itemManagerRepository->update($request->all(), $id);

        Flash::success(trans('flash.controller.update_success', ['model' => 'Item Manager']));

        return redirect(route('itemManagers.index'));
    }

    /**
     * Remove the specified ItemManager from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $itemManager = $this->itemManagerRepository->findWithoutFail($id);

        if (empty($itemManager)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Item Manager']));

            return redirect(route('itemManagers.index'));
        }

        $this->itemManagerRepository->delete($id);

        Flash::success(trans('flash.controller.delete_success', ['model' => 'Item Manager']));

        return redirect(route('itemManagers.index'));
    }
}
